package com.lcj.dr.service.impl;

import com.lcj.dr.controller.form.DriverWalletInfoForm;
import com.lcj.dr.db.dao.WalletDao;
import com.lcj.dr.db.dao.WalletIncomeDao;
import com.lcj.dr.db.dao.WalletPaymentDao;
import com.lcj.dr.service.WalletService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WalletServiceImpl implements WalletService {

    @Resource
    private WalletDao walletDao;

    @Resource
    private WalletIncomeDao walletIncomeDao;

    @Resource
    private WalletPaymentDao walletPaymentDao;

    @Override
    public Map searchInfo(DriverWalletInfoForm form) {

        List<Map> record = new ArrayList<>();
        if("income".equals(form.getType()) || "all".equals(form.getType())) {
            List<Map> walletIncomeList = walletIncomeDao.search(form.getDriverId());
            record.addAll(walletIncomeList);
        }
        if("payment".equals(form.getType()) || "all".equals(form.getType())) {
            List<Map> walletPaymentList = walletPaymentDao.search(form.getDriverId());
            record.addAll(walletPaymentList);
        }
        Map<String, Object> res = new HashMap<>();
        res.put("records", record);

        Double balance = walletDao.selectBalance(form.getDriverId());
        res.put("balance", balance);
        Double incomeTotalInMonth = walletIncomeDao.searchIncomeTotalInMonth(form.getDriverId());
        res.put("incomeTotalInMonth", incomeTotalInMonth);
        Double paymentTotalInMonth = walletPaymentDao.searchPaymentTotalInMonth(form.getDriverId());
        res.put("paymentTotalInMonth", paymentTotalInMonth);
        Double incomeTotalInDay = walletIncomeDao.searchIncomeTotalInDay(form.getDriverId());
        res.put("incomeTotalInDay", incomeTotalInDay);

        return res;
    }
}
